<?php
// @formatter:off
/**
 * @file ct.image.updatenames.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: ct.image.updatenames.php 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/cron/ct.image.updatenames.php $
 */
// @formatter:on

class WCImagesUpdateNames extends WCCronTool {
	public function run($spacer = "") {
		foreach(WCGroupsHolder::I()->items() as $group) {
			if(is_readable($group->root)) {
				echo "{$spacer}Checking group '{$group->name}' ({$group->id}):\n";
				foreach($group->directoriesFull() as $directory) {
					foreach($directory->imagesFull() as $image) {
						if($image->next_name) {
							echo "{$spacer}\tRenaming '{$image->name}' in '{$image->directory()->name}' to '{$image->next_name}': ";
							if($image->setNextName()) {
								echo WCColorText::ShellGreen("Done")."\n";
							} else {
								echo WCColorText::ShellRed("Failed")."\n";
							}
						}
					}
				}
			}
		}
	}
	public function showHelp($spacer = "") {
		echo "{$spacer}This tool seeks for any image marked to be renamed and attempts to\n";
		echo "{$spacer}rename it.\n\n";
		echo "{$spacer}It requires no extra parameters.\n";
	}
	protected function loadOptions() {
		$this->_optionsLoaded = true;
	}
}
?>